#define _CRT_SECURE_NO_WARNINGS

int binary_search(int arr[], int num, int x)
{
	int ret = -1;
	int left = 0;
	int right = num;

	while (left <= right)
	{
		int mid = left + (right - left) / 2;
		if (x < arr[mid])
		{
			right = mid - 1;
		}
		else if (x > arr[mid])
		{
			left = mid + 1;
		}
		else
		{
			ret = mid;
			break;
		}
	}

	return ret;
}